// Copyright (c) 2011 Blue Onion Software, All rights reserved
using System;
using System.Web.UI.WebControls;
using BlueOnionSoftware.Bloget.Properties;

namespace BlueOnionSoftware.Bloget
{
    internal class LicenseView : View
    {
        internal LicenseView(Bloget blogetArg)
            : base(blogetArg)
        {
        }

        protected override string RootClassId()
        {
            return "license-view";
        }

        protected override void ShowView()
        {
            Bloget.WriteLine(Resources.LicenseAgreement);

            var accept = new Button {Text = Resources.LicenseViewAccept};
            accept.Click += AcceptClick;

            Bloget.WriteLine("<p style=\"text-align:center\">");
            Bloget.Controls.Add(accept);
            Bloget.WriteLine("</p>");
        }

        private void AcceptClick(object sender, EventArgs ea)
        {
            var blog = new Blog(Bloget.Blog) {LicenseAgreement = true}; // copy to protect readers
            Log.LicenseAgreementAccepted(Bloget);
            blog.Save();
            Bloget.Redirect(Bloget.Page.Request.Path);
        }
    }
}